export default {
  getCharLength(str) {
    return str.replace(/[^\x00-\xff]/g, 'rr').length
  },
  subStr(str, charLength) {
    if (this.getCharLength(str) <= charLength) return str
    var m = Math.floor(charLength / 2)
    for (var i = m; i < str.length; i++) {
      if (this.getCharLength(str.substr(0, i)) >= charLength) {
        return str.substr(0, i)
      }
    }
    return str
  }
}
